package com.yantong.controller.api;

import com.yantong.annotation.Auth;
import com.yantong.annotation.LoginUser;
import com.yantong.controller.BaseController;
import com.yantong.pojo.Member;
import com.yantong.pojo.MemberWxcard;
import com.yantong.pojo.bo.WxCardRespBo;
import com.yantong.result.ResultVo;
import com.yantong.service.MemberService;
import com.yantong.service.StoreService;
import com.yantong.service.WxService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author: juzi
 * @date: 2021/10/25
 * @time: 16:12
 */
@ApiIgnore
@Controller
@RequestMapping("/wxapi/wxCard")
public class ApiWxCardController extends BaseController {

    @Autowired
    private WxService wxService;
    @Autowired
    private StoreService storeService;
    @Autowired
    private MemberService memberService;


    /**
     * 查询用户是否已领取卡券
     * @param member
     * @param teamId
     * @param type
     * @param cardId
     * @return
     */
    @ResponseBody
    @GetMapping("/wxCardFlag")
    @Auth
    public ResultVo wxCardFlag(@ApiIgnore @LoginUser Member member, Long teamId, int type, String cardId) {
        List<MemberWxcard> list = wxService.wxCardFlag(member, teamId,type,cardId);
        return ResultVo.ok().put("list", list);
    }

    /**
     * 领取卡包
     * @param member
     * @param shopMemberId
     * @param type
     * @return
     */
    @ResponseBody
    @GetMapping("/getShopCardInfo")
    @Auth
    public ResultVo getShopCardInfo(@LoginUser Member member, Long shopMemberId, int type) {
        if (shopMemberId == null) {
            return ResultVo.error("门店信息不能为空");
        }

        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", storeService.getShopCardInfo(member, shopMemberId, type));
        return resultVo;
    }

    /**
     * 添加前端添加成功的卡券列表接口
     * @param member
     * @param wxCardRespVo
     * @return
     */
    @ResponseBody
    @PostMapping("/addWxCardList")
    @Auth
    public ResultVo addWxCardList(@ApiIgnore @LoginUser Member member, @RequestBody WxCardRespBo wxCardRespVo) {
        wxService.addWxCardList(member, wxCardRespVo.getWxCardList(),wxCardRespVo.getType());
        return ResultVo.ok();
    }


    /**
     * 获取添加会员卡所需要的参数
     * @param centerId
     * @param shopMemberId
     * @param type
     * @return
     */
    @ResponseBody
    @GetMapping("/getAddCardExt")
//    @Auth
    public ResultVo getAddCardExt(Long centerId, Long shopMemberId,int type) {
        ResultVo resultVo = new ResultVo();
        resultVo.put("success", true);
        resultVo.put("data", storeService.getAddCardExt(centerId, shopMemberId,type));
        return resultVo;
    }
    @ApiOperation(value = "查询用户是否已领取该商户卡券")
    @ResponseBody
    @GetMapping("/merchantWxCardFlag")
    @Auth
    public ResultVo merchantWxCardFlag(@ApiIgnore @LoginUser Member member,String teamSeqId) {
        Member teamMember = memberService.getTmByTeamSeqId(teamSeqId);
        List<MemberWxcard> memberWxcardList = wxService.selectbymidAndCentreIdAndType(member.getId(),teamMember.getCentreId(),2);
        return ResultVo.ok().put("list", memberWxcardList);
    }
}
